package action;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class common {
	
	public static WebDriver openBrowser(String url, String browser) {
		WebDriver d = null;
		if(browser.equals("ff")){
			d = new FirefoxDriver();
			d.get(url);
		}
		
		//set timeout n maximize window
		d.manage().timeouts().implicitlyWait(config.cf_shortTime, TimeUnit.SECONDS);
		d.manage().window().maximize();
		return d;
	}
	
	public static void click(WebDriver d, String xpath ) {
		d.findElement(By.xpath(xpath)).click();
	}
	
	public static void type(WebDriver d, String xpath, String text) {
		d.findElement(By.xpath(xpath)).sendKeys(text);		
	}

	public static void waitForElement(WebDriver d, String element) {
		WebDriverWait wait = new WebDriverWait(d,config.cf_longTime);
		WebElement e = d.findElement(By.xpath(element));
		wait.until(ExpectedConditions.visibilityOf(e));		
	}
	
	public static void waitForPageLoad(WebDriver d) {
		
	}
}
